package com.gzdh.device.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gzdh.device.comm.vo.Result;
import com.gzdh.device.system.entity.SysUser;
import com.gzdh.device.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("api/system/v1")
public class SysUserController {


    @Autowired
    SysUserService sysUserService;

    @GetMapping("getUserInfo")
    public Result<Object> getUserInfo(Authentication authResult) {
        Result<Object> result = new Result<>();
        SysUser sysUser = sysUserService.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getUserName, authResult.getPrincipal()));
        result.setResult(sysUser);
        return result;
    }


    @GetMapping("getPermCode")
    public Result<Object> getPermCode(Authentication authResult) {
        Result<Object> result = new Result<>();
        SysUser sysUser = sysUserService.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getUserName, authResult.getPrincipal()));
        result.setResult(sysUserService.getPermCode(sysUser.getId()));
        return result;
    }


    @GetMapping("getMenuList")
    public Result<Object> getMenuList(Authentication authResult) {
        Result<Object> result = new Result<>();
        SysUser sysUser = sysUserService.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getUserName, authResult.getPrincipal()));
        result.setResult(sysUserService.getUserMenu(sysUser.getId()));
        return result;
    }
}
